#!/bin/bash
s11u2='s11u2'
s12='s12'
s11u2_inited=false
s12_inited=false
log=init_update_all.log
if [ -f $log ]; then
    rm $log
fi
for ((build=1; build<=30; build++))
do
    #if build < 10, add 0 to build_str
    if [ $build -lt 10 ]; then
        build_str='0'${build}
    else
        build_str="${build}"
    fi

    #s12 not inited, init it, and flag it true; else already inited, update build
    if ! $s12_inited; then
        ./manage.py init_pkg_db -o ${s12} -b ${build_str} &>>$log
        exit_code=$?
        if [ 0 -eq $exit_code ]; then
            s12_inited=true
            echo 'init s12 build '$build_str
        fi
    else
        ./manage.py update_build -o ${s12} -b ${build_str} &>>$log
        exit_code=$?
        if [ 0 -eq $exit_code ]; then
            echo 'update s12 build '$build_str
        else
            echo 'fail to update s12 build '$build_str
        fi

        ./manage.py collect_depend -o ${s12} -b ${build_str} &>>$log
        exit_code=$?
        if [ 0 -eq $exit_code ]; then
            echo 'success collect depend s12 build '$build_str
        else
            echo 'fail collect depend s12 build '$build_str
        fi
    fi

    #s11u2 not inited, init it, and flag it true; else already inited, update build
    if ! $s11u2_inited; then
        ./manage.py init_pkg_db -o ${s11u2} -b ${build_str} &>>$log
        exit_code=$?
        if [ 0 -eq $exit_code ]; then
            s11u2_inited=true
            echo 'init s11u2 build '$build_str
        fi
    else
        ./manage.py update_build -o ${s11u2} -b ${build_str} &>>$log
        exit_code=$?
        if [ 0 -eq $exit_code ]; then
            echo 'update s11u2 build '$build_str
        else
            echo 'fail to update s11u2 build '$build_str
        fi
<<<<<<< HEAD

        ./manage.py collect_depend -o ${s11u2} -b ${build_str} &>>$log
        exit_code=$?
        if [ 0 -eq $exit_code ]; then
            echo 'success collect depend s11u2 build '$build_str
        else
            echo 'fail collect depend s11u2 build '$build_str
        fi
=======
>>>>>>> origin/master
    fi
done
